﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Castle.ActiveRecord;
using System.ComponentModel;
using Light.Utility;

namespace Light.Framework.Model
{
    /// <summary>
    /// 字典实体
    /// </summary>
    [ActiveRecord("Dictionary")]
    public class Dictionary
    {
        /// <summary>
        /// 代码
        /// </summary>
        [PrimaryKey]
        public virtual string Code { get; set; }

        /// <summary>
        /// 名称
        /// </summary>
        [Property]
        public virtual string Name { get; set; }


        /// <summary>
        /// 显示顺序
        /// </summary>
        [Property]
        public virtual string DisplayIndex { get; set; }

        public override bool Equals(object obj)
        {
            return ((Dictionary)obj).Code == this.Code;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }



    /// <summary>
    /// 地区（华东、华南、西南....）
    /// </summary>
    [ActiveRecord(Table = "Dictionary", Where = "FType='Area' AND IsVisible=1")]
    public class Area : Dictionary
    {

    }

    /// <summary>
    /// 省份
    /// </summary>
    [ActiveRecord(Table = "Dictionary", Where = "FType='Province' AND IsVisible=1")]
    public class Province : Dictionary
    {
        /// <summary>
        /// 所属地区
        /// </summary>
        [BelongsTo("ParentCode", NotFoundBehaviour = NotFoundBehaviour.Ignore)]
        public Area Area { get; set; }
    }

    /// <summary>
    /// 城市
    /// </summary>
    [ActiveRecord(Table = "Dictionary", Where = "FType='City' AND IsVisible=1")]
    public class City : Dictionary
    {
        /// <summary>
        /// 所属省份
        /// </summary>
        [BelongsTo("ParentCode", NotFoundBehaviour = NotFoundBehaviour.Ignore)]
        public Province Province { get; set; }
    }

    /// <summary>
    /// 行政区
    /// </summary>
    [ActiveRecord(Table = "Dictionary", Where = "FType='District' AND IsVisible=1")]
    public class District : Dictionary
    {
        /// <summary>
        /// 所属城市
        /// </summary>
        [BelongsTo("ParentCode", NotFoundBehaviour = NotFoundBehaviour.Ignore)]
        public City City { get; set; }
    }

    /// <summary>
    /// 银行
    /// </summary>
    [ActiveRecord(Table = "Dictionary", Where = "FType='Bank' AND IsVisible=1")]
    public class Bank : Dictionary
    {

    }
}
